package 其他;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 *
 */
public class Thread {
    private static ThreadPoolExecutor mExecutors =
            new ThreadPoolExecutor(0, 6,
                    6L, TimeUnit.MILLISECONDS,
                    new LinkedBlockingQueue<Runnable>());

    public static void main(String[] args) {
        mExecutors.allowCoreThreadTimeOut(true);
        test();
        System.gc();
    }

    public static void test() {
        for (int i = 0; i < 10; i++) {
            new SimpleClass(i).runTask();
        }
    }

    static class SimpleClass {
        private final int mIndex;


        public SimpleClass(int index) {
            mIndex = index;
        }

        public void runTask() {
            mExecutors.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("[" + mIndex + "] execute");
                }
            });
        }
    }


}
